﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;
using HZ.Supervise.IBLL; 
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model.Query;
using System.Data;

namespace HZ.Supervise.Web.SystemManage
{
    public partial class GoodsListUpdate : BasePage
    {
        public GoodsListUpdate()
        {
            this.ModuleNo = Module.基础信息库.ToString();
            PageOperateType = OperateType.药品库信息.ToString();
        }

        IBLL_ProcureCatalog ip = BLLFactory.IBLL_ProcureCatalog();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                setBind();

            }
        }

        
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            ///setBind();
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            setBind();
        }

        private Model.View.ProcureCatalog getQuery()
        {
            //获取查询条件
            Model.View.ProcureCatalog procureCatalog = new HZ.Supervise.Model.View.ProcureCatalog();
            procureCatalog.ProcureCatalogID = txtProcureCatalog.Text.Trim();
            procureCatalog.CompanyName_SC = txtProduceCompany_SC.Text.Trim();
            procureCatalog.QualityLevel = txtQualityLevel.Text.Trim();
            procureCatalog.MedicineModelName = txtMedicineModel.Text.Trim();
            procureCatalog.GoodsName = txtGoodsName.Text.Trim();
            if (HZ.Common.zhHansUtil.HaveChineseCode(txtProductName.Text) == true)
            {
                procureCatalog.ProductName = txtProductName.Text.Trim();
            }
            else
            {
                procureCatalog.PinyinCode = txtProductName.Text.Trim();
            }
            //procureCatalog.ProjectID = ddlProject.SelectedItem.Value;
            if (!string.IsNullOrEmpty(txtProcurePrice.Text))
            {
                procureCatalog.ProcurePrice = Convert.ToDecimal(txtProcurePrice.Text.Trim());
            }
            //if (ddlHosShuXing.SelectedValue != "-1")//药品属性
            //{
            //    if (ddlHosShuXing.SelectedValue == "")
            //    {
            //        procureCatalog.Append = " SortSource ='' ";
            //    }
            //    else
            //    {
            //        procureCatalog.SortSource = Convert.ToInt32(ddlHosShuXing.SelectedValue);
            //    }
            //}
            if (ddlIsUsing.SelectedValue != "-1")//是否启用
            {
                if (ddlIsUsing.SelectedValue == "全部")
                {

                }
                else
                {
                    procureCatalog.IsUsing = Convert.ToBoolean(ddlIsUsing.SelectedValue);
                }
            }
            procureCatalog.Outlookc = txtPack.Text.Trim();
            if (!string.IsNullOrEmpty(txtFactor.Text))
            {
                procureCatalog.Factor = Convert.ToInt32(txtFactor.Text.Trim());
            }

            //procureCatalog.SortFields = " ProductName asc";
            return procureCatalog;

        }
        /// <summary>
        /// 根据查询条件绑定采购目录
        /// </summary>
        private void setBind()
        {
            Model.View.ProcureCatalog procureCatalog = new Model.View.ProcureCatalog();
            procureCatalog = getQuery();
            int totalCount = 0; 
            try
            {

                DataTable dt = ip.GetProcureCatalogByWhere(procureCatalog, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
                AspNetPager1.RecordCount = totalCount;
                gvwProduceCatalog.DataSource = dt;
                gvwProduceCatalog.DataBind();
            }
            catch (Exception ex)
            {
                //PageError(ex.Message, "");
            }
        }
        /// <summary>
        /// 撤费目录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void btnDel_Click(object sender, EventArgs e)
        //{
        //    string ids = Request["checkbox1"];

        //    if (!string.IsNullOrEmpty(ids))
        //    {
        //        string[] arraryIds = ids.Split(',');
        //        foreach (string Item in arraryIds)
        //        {
        //            Model.View.ProcureCatalog tmpProcureCatalog = pbCtrl.GetProcureCatalogByID(Item);

        //            IBLL_ProcureCatalogAreaPS ig = Factory.BLL_ProcureCatalogAreaPS();
        //            int nSuccess = ig.UPdateProcureCatalogByID(tmpProcureCatalog.ProcureCatalogID, 0);
        //            if (nSuccess == 0)
        //            {
        //                PageError("数据操作失败！", "");
        //            }

        //        }
        //    }
        //    setBind();
        //}

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            Model.View.ProcureCatalog procureCatalog = new Model.View.ProcureCatalog();
            procureCatalog = getQuery();
            int totalCount = 0;
            try
            {

                DataTable dt = ip.GetProcureCatalogByWhere(procureCatalog, 1, 0, out totalCount);
                ExportFile.Instance.ExportData(dt, gvwProduceCatalog, this.Page);
            }
            catch (Exception ex)
            {
                //PageError(ex.Message, "");
            }
            
        }

        /// <summary>
        /// 恢复目录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void btnReSet_Click(object sender, EventArgs e)
        //{
        //    string ids = Request["checkbox1"];

        //    if (!string.IsNullOrEmpty(ids))
        //    {
        //        string[] arraryIds = ids.Split(',');
        //        foreach (string Item in arraryIds)
        //        {
        //            Model.View.ProcureCatalog tmpProcureCatalog = pbCtrl.GetProcureCatalogByID(Item);

        //            IBLL_ProcureCatalogAreaPS ig = Factory.BLL_ProcureCatalogAreaPS();
        //            int nSuccess = ig.UPdateProcureCatalogByID(tmpProcureCatalog.ProcureCatalogID, 1);
        //            if (nSuccess == 0)
        //            {
        //                PageError("数据操作失败！", "");
        //            }

        //        }
        //    }
        //    setBind();

        //}

        //protected void gvwProduceCatalog_RowDataBound(object sender, GridViewRowEventArgs e)
        //{
        //    if (e.Row.RowType == DataControlRowType.DataRow)
        //    {
        //        if (e.Row.Cells[20].Text != "在线")
        //            e.Row.Cells[20].Text = "不在线";
        //    }
        //}
    }
}
